package com.example.springboot.controller.v2;

import com.example.springboot.mapping.ApiVersion;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 两个需求
 * 1. 在请求投中设置 version版本，根据版本请求 接口
 * 2. 在请求参数中，存在版本参数，将请求转发给标准版本
 *
 * @author by Mr. Li 2021/1/30 18:48
 */
@RestController
@Slf4j
public class ApiVersionController {

    @ApiVersion(version = "v1")
    @RequestMapping("/api/test")
    public String test() {
        log.info(">>>>>>>>>>>>>>> v1 version running <<<<<<<<<<<<<<<<<<<<<<<");
        return "v1";
    }

    @ApiVersion(version = "v2")
    @RequestMapping("/api/test")
    public String test2() {
        log.info(">>>>>>>>>>>>>>> v2 version running <<<<<<<<<<<<<<<<<<<<<<<");
        return "v2";
    }


    /**
     * 测试请求路径中存在v3
     *
     * @return
     */
    @ApiVersion(version = "v3")
    @RequestMapping("/api/test")
    public String test3() {
        log.info(">>>>>>>>>>>>>>> v3 version running <<<<<<<<<<<<<<<<<<<<<<<");
        return "v3";
    }

}
